
from matplotlib.pylab import mpl
from pygal_maps_world.i18n import COUNTRIES

def set_cn_font():
    mpl.rcParams['font.sans-serif'] = ['SimHei']  #令支持中文 设置字体为宋体


def color_to_rgb(colorStr:str):
    """把网页颜色，转换成rgb颜色"""
    colorStr = colorStr.replace("#","")
    rgbColor = tuple([int('0x'+colorStr[i:i+2],16) for i in range(0,len(colorStr),2)])
    
    return rgbColor

def to_mpl_color(colorStr:str):
    """把网页颜色转换成rgb小数的形式"""
    rgbColor = color_to_rgb(colorStr)
    return tuple([float(i/255) for i  in rgbColor])


def get_country_code(country_name):
    for code,name in COUNTRIES.items():        
        if country_name==name:
            return code
    
    return None
